<?php

/**
 * class ToolBarHelper
 * pntrinh87@gmail.com
 */

class ToolBarHelper
{
    var $html   = '';
    var $title  = '';
    var $title_model=false;
    var $act;
    var $ajax   ='false';
    var $tabs   = array();
    function ToolBarHelper($act)
    {
        $this->act=$act;
    }
    function setTitle($title,$title_model=false)
    {
        $this->title_model    = $title_model;
        $this->title        = $title;
    }
    function getTitle()
    {
        return $this->title;
    }
    function getTitleModel()
    {
        return $this->title_model;
    }

    function setSubmitAjax($ajax=false)
    {
        if($ajax==true)
        {
            $this->ajax='true';
        }else
        {
            $this->ajax='false';
        }
    }
    
    /**
     * function: addNew($task = 'add', $alt = 'New',$url=null)
     * @param $task: default : add
     * @param $alt : text display
     * @param $url: add url if has
     */
    function addNew($task = 'add', $alt = 'New',$url=null)
    {
        global $module;
        if(!empty($module))
        {
            $task='?module='.$module.'&opt='.$task.'&'.$url;
        }else
        {
            $task='?opt='.$task.'&'.$url;
        }
        $this->html.='<a class="icon" href="'.$task.'">';
        $this->html.='<span class="icon_new"></span>';
        $this->html.='<span class="text">'.$alt.'</span></a>';
        return $this->html;
    }
    
    function background($task='background',$alt='Background',$url=null)
    {
        global $module;
        if(!empty($module))
        {
            $task='?module='.$module.'&opt='.$task.'&'.$url;
        }else
        {
            $task='?opt='.$task.'&'.$url;
        }
        $this->html.='<a class="icon" href="'.$task.'">';
        $this->html.='<span class="icon_background"></span>';
        $this->html.='<span class="text">'.$alt.'</span></a>';
        return $this->html;
    }

    function addUser($task = 'add', $alt = 'New',$url=null)
    {
        global $module;
        if(!empty($module))
        {
            $task='?module='.$module.'&opt='.$task.'&'.$url;
        }else
        {
            $task='?opt='.$task.'&'.$url;
        }
        $this->html.='<a class="icon" href="'.$task.'">';
        $this->html.='<span class="icon_adduser"></span>';
        $this->html.='<span class="text">'.$alt.'</span></a>';
        return $this->html;
    }

    function Edit($task = 'edit', $alt = 'Edit',$url=null)
    {
        global $module;
        $this->html.='<a id="editbut" class="icon" onclick="location=\'?module='.$module.'&opt='.$task.'&'.$url.'\'">';
        $this->html.='<span class="icon_edit"></span>';
        $this->html.='<span class="text">'.$alt.'</span></a>';
        return $this->html;
    }

    function Delete($task = 'delete', $alt = 'Delete',$url=null)
    {
        global $module;
        $this->html.='<a id="delbut" class="icon" onclick="';
        if($url!=null)
        {
            $this->html.=' if(confirm(\'Do you want delete category?\'))';
        }else
        {
            $this->html.='if(!isChecked())alert(\'Please make a selection from the list to delete\');';
            $this->html.=' else if(confirm(\'Do you want delete selected?\'))';
        }
        $this->html.='submitform({ajax:false,goback:true,act:\'?module='.$module.'&opt='.$task.'&'.$url.'\'})">';
        $this->html.='<span class="icon_del"></span>';
        $this->html.='<span class="text">'.$alt.'</span></a>';
        return $this->html;
    }

    function Apply($alt = 'Apply',$opt=4)
    {
        $this->html.='<a id="applybut" class="icon" onclick="submitform({ajax:'.$this->ajax.',goback:'.$opt.'})">';
        $this->html.='<span class="icon_apply"></span>';
        $this->html.='<span class="text">'.$alt.'</span></a>';
        return $this->html;
    }
    
    function Save($alt = 'Save',$opt=3)
    {
        $this->html.='<a id="savebut" class="icon" onclick="submitform({ajax:'.$this->ajax.',goback:'.$opt.'})">';
        $this->html.='<span class="icon_save"></span>';
        $this->html.='<span class="text">'.$alt.'</span></a>';
        return $this->html;
    }

    function Cancel($url='javascript:history.back();',$alt = 'Cancel')
    {
        $this->html.='<a id="cancelbut" class="icon" href="'.$url.'">';
        $this->html.='<span class="icon_cancel"></span>';
        $this->html.='<span class="text">'.$alt.'</span></a>';
        return $this->html;
    }

    function Back($url='javascript:history.back();',$alt = 'Back')
    {
        $this->html.='<a id="backbut" class="icon" href="'.$url.'">';
        $this->html.='<span class="icon_back"></span>';
        $this->html.='<span class="text">'.$alt.'</span></a>';
        return $this->html;
    }
    
    function addTab($name)
    {
        if(is_array($name))
        {
            $this->tabs  = $name;
        }else
        {
            $this->tabs[]= $name;   
        }        
    }
    
    function getTabs()
    {
        return (count($this->tabs)>0)? $this->tabs : false;
    }
    
    function getHTML()
    {
        return $this->html;
    }
}

?>